using System;

using NUnit.Framework;

namespace Source.Tests
{
    public static class Util
    {
        public static void AssertThrows<T>(Action action) where T : Exception
        {
            var exception = GetThrownException<T>(action);

            if (exception == null)
            {
                Assert.Fail("Expected exception of type {0} not thrown", typeof(T).FullName);
            }
        }

        public static T GetThrownException<T>(Action action) where T : Exception
        {
            try
            {
                action();
            }
            catch (T e)
            {
                return e;
            }

            return null;
        }
    }
}